package log_api

import (
	"fmt"
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"
	"gin_study_blog/plugins/log_stash"
	"github.com/gin-gonic/gin"
)

// LogDeleteView 日志删除
func (LogApi) LogDeleteView(c *gin.Context) {
	var re models.RemoveRequest

	err := c.ShouldBindJSON(&re)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}
	var logList []*log_stash.LogStashModel
	// 查询文件是否存在数据库中
	count := common.DB.Find(&logList, re.IdList).RowsAffected
	if count == 0 {
		http.FailWithMessage("日志不存在", c)
		return
	}
	// 在删除数据库数据
	common.DB.Delete(&logList)
	http.IsOkWithMessage(fmt.Sprintf("共删除 %d 日志", count), c)
}
